<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="skladiscenje.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <META http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>SKLADISCENJE systems</title>
        <LINK href="CSS/style.css" rel="stylesheet" type="text/css" />
        <LINK REL="SHORTCUT ICON" HREF="images/favicon.ico" />
        <script type="text/javascript">
		function tiskajInZapri(id, kolicina){
			self.location = "potrditvenoOkno.jsp?id="+id+"&kolicina="+kolicina;
			self.print();
			self.onafterprint = null;
			self.close();
		}
		function shraniInZapri(id, kolicina){
			self.location = "potrditvenoOkno.jsp?id="+id+"&kolicina="+kolicina;
			self.close();
		}
		function zapri(){
			self.close();
		}
		</script>
    </head>
        
    <body>
		<%
		if(request.getParameter("potrdi") != null){
			if((request.getParameter("dropdownBlago") != null) && (request.getParameter("dodatnaKolicina") != null)){
				String porociloO = request.getParameter("porociloO");
				String sprejetaIzdana = "";
				int id = Integer.parseInt(request.getParameter("dropdownBlago"));
				int  sI = 1;
				Uporabnik uporabnik = (Uporabnik) session.getAttribute("uporabnik");
				Blago blago = Evidenca.getBlagoById(id);
				int dodatnaKolicina = Integer.parseInt(request.getParameter("dodatnaKolicina"));
				if(porociloO.equals("sprejemu")){
					sprejetaIzdana = "Sprejeta";
					sI = 1;
					if(dodatnaKolicina < 0){
						dodatnaKolicina *= -1;
					}
				}else{
					sI = 0;
					sprejetaIzdana = "Izdana";
					if(dodatnaKolicina > 0){
						dodatnaKolicina *= -1;
					}
				}
				%>
				<h1>Poročilo o <%= porociloO %> blaga</h1><br />
				<h3>Blago je sprejel: <%= uporabnik.getIme() %> <%= uporabnik.getPriimek() %></h3><br />
				ID skladiščnika: <%= uporabnik.getID() %><br /><hr />
				<h3>Ime blaga: <%= blago.getIme() %></h3><br />
				Sektor blaga: <%= blago.getSektor() %><br />
				Tip blaga: <%= blago.getImeTip() %><br /><hr />
				Trenutna kolicina: <%= blago.getKolicina() %> <%= blago.getImeEnota() %><br />
				<%= sprejetaIzdana %> kolicina: <%= dodatnaKolicina %> <%= blago.getImeEnota() %><br />
				<h2>Nova kolicina: <%= blago.getKolicina() + dodatnaKolicina %> <%= blago.getImeEnota() %></h2><br />
				
				<input type="submit" name="zapri" value="Prekliči" onCLick="zapri()" />
				<input type="submit" name="TiskajShraniInZapri" value="Potrdi in tiskaj" onClick="tiskajInZapri(<%= id %>, <%= blago.getKolicina() + dodatnaKolicina %>)" />
				<input type="submit" name="ShraniInZapri" value="Potrdi" onClick="shraniInZapri(<%= id %>, <%= blago.getKolicina() + dodatnaKolicina %>)" />
				<%
			}
		}
		if((request.getParameter("id") != null) || (request.getParameter("kolicina") != null)){
			int id = Integer.parseInt(request.getParameter("id"));
			int kolicina = Integer.parseInt(request.getParameter("kolicina"));
			Evidenca.prevzemIzdajaBlaga(id, kolicina);
		}
		%>
	</body>
</html>